package com.zz.inventory.controller;

import java.util.List;
import java.io.IOException;

import com.zz.inventory.domain.ServiceResult;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.zz.inventory.domain.Labs;
import com.zz.inventory.service.ILabsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 机房信息Controller
 * 
 * @author ruoyi
 * @date 2025-07-01
 */
@RestController
@RequestMapping("/labs")
public class LabsController extends BaseController
{
    @Autowired
    private ILabsService labsService;

    /**
     * 查询机房信息列表
     */
    @RequiresPermissions("schoolmanage:labs:list")
    @GetMapping("/list")
    public TableDataInfo list(Labs labs)
    {
        startPage();
        List<Labs> list = labsService.selectLabsList(labs);
        return getDataTable(list);
    }

    /**
     * 导出机房信息列表
     */
    @RequiresPermissions("schoolmanage:labs:export")
    @Log(title = "机房信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Labs labs)
    {
        List<Labs> list = labsService.selectLabsList(labs);
        ExcelUtil<Labs> util = new ExcelUtil<Labs>(Labs.class);
        util.exportExcel(response, list, "机房信息数据");
    }

    /**
     * 获取机房信息详细信息
     */
    @RequiresPermissions("schoolmanage:labs:query")
    @GetMapping(value = "/{labId}")
    public AjaxResult getInfo(@PathVariable("labId") Long labId)
    {
        return success(labsService.selectLabsByLabId(labId));
    }

    /**
     * 新增机房信息
     */
    @RequiresPermissions("schoolmanage:labs:add")
    @Log(title = "机房信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Labs labs)
    {
        return toAjax(labsService.insertLabs(labs));
    }

    /**
     * 修改机房信息
     */
    @RequiresPermissions("schoolmanage:labs:edit")
    @Log(title = "机房信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Labs labs)
    {
        return toAjax(labsService.updateLabs(labs));
    }

    /**
     * 删除机房信息
     */
    @RequiresPermissions("schoolmanage:labs:remove")
    @Log(title = "删除机房信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{labId}")
    public ServiceResult<Integer> remove(@PathVariable Long labId) {
        return labsService.deleteLabsByLabId(labId);
    }
}
